<?php
/* @var $this yii\web\View */
use app\models\Mall;
use app\widgets\MallMBottomToolbarWidget;
use yii\helpers\Url;

$web = Url::base();
$integral_unit = \app\models\Mall::getCurrentInstitutionIntegralUnit();
$integral_rate = Mall::getCurrentInstitutionIntegralRate();
$institution_code = Mall::getCurrentInstitutionCode();
$site_name = \app\models\Mall::getCurrentInstitutionSiteName();
$userIntegral = \app\models\User::getUserIntegral(Mall::getCurrentUserId());
$this->title = $site_name;


///场景9个  1-5  上面5个链接    6-9 4个下面链接 排除掉
$scene = [];
$extendCategoryList_tmp = [];
$scene_i = 1;
$scene = array_pad($scene, 10, ['type' => '', 'id' => '', 'name' => '', 'image_url' => '']);

foreach ($extendCategoryList as $item) {
    $identifier_code = $item['identifier_code'];
    $is_find = false;
    for ($i = 1; $i <= 9; $i++) {
        if ($identifier_code == 'a-' . $i) {
            $scene[$i] = $item;
            $is_find = true;
            break;
        }
    }
    if ($is_find == false) {
        $extendCategoryList_tmp[] = $item;
    }

}
//var_dump($scene);exit;
//var_dump($extendCategoryList_tmp);exit;
$extendCategoryList = $extendCategoryList_tmp;

$extendCategoryList_1 = [];
$extendCategoryList_2 = [];
foreach ($extendCategoryList as $item) {
    $link_url = $item['link_url'];
    if ($item['type'] == '1') {
        $extendCategoryList_1[] = $item;
    }
    if ($item['type'] == '2') {
        $extendCategoryList_2[] = $item;
    }
}
?>


<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall-m/index.css"/>
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall-m/cross-title.css"/>
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall-m/theme-bs/index-bs.css"/>
<style type="text/css">

</style>
<script>
    var app_download = 0;
    $(function ($) {

//        mySessionStorage
        if (mySessionStorage.hasOwnProperty('app_download')) {
            app_download = mySessionStorage.app_download;
        }
        if (is_weixin()) {
            if (mySessionStorage.hasOwnProperty('app_download') == false) {
                app_download = 1;
            }

        } else {
            var inst_code = getUrlParamValue(window.location.href, 'institution_code');
            if (inst_code != 'jg001393') {//jg000002  jg001393
                if (mySessionStorage.hasOwnProperty('app_download') == false) {
                    app_download = 1;
                }
            }
        }
        mySessionStorage.setItem('app_download', app_download);
        if (app_download == 1) {
            $('.header-download').show();
        }

    });
</script>
<div class="main">

    <div class="header-fixed">
        <div class="header-download" style="display: none;">
            <div class="left">
                <a class="close-btn-bs" href="javascript:$('.header-download').hide();app_download=0;"> <img src="<?= $web ?>/images/mall-m/theme-bs/close-btn-bs.png"/></a>
                <img class="baisheng-logo" src="<?= $web ?>/images/mall-m/theme-bs/baisheng-logo-icon.png"/>
                <p>下载百胜福利APP</p>
            </div>
            <div class="right">
                <a href="<?= Url::to(['mall-m/bs-android-iphone-download']) ?>?institution_code=<?= $institution_code ?>" class="now-btn">立即下载</a>
            </div>
        </div>
        <div class="header-fixed-bg"></div>
        <div class="header-fixed-content">
            <a class="search" href="<?= Url::to(['mall-m/search', 'institution_code' => $institution_code]) ?>">
                <img src="<?= $web ?>/images/mall-m/index-icon-search.png">
                <label>大闸蟹</label>
            </a>
            <?php
            if (Mall::getCurrentUser() == null) {
                ?>
                <div class="login-frame">
                    <a href="<?= Url::to(['mall-m/login']) ?>" class="login-link">
                        <img src="<?= $web ?>/images/mall-m/index-icon-integra2.png">
                        <p>登录</p>
                    </a>
                </div>
                <?php
            } else {
                ?>
                <div class="integral-frame">
                    <div class="integral-frame-bg"></div>
                    <div class="integral-frame-content">
                        <img class="icon" src="<?= $web ?>/images/mall-m/index-icon-integral.png">
                        <div class="value-frame">
                            <div class="title"><?= $integral_unit ?>余额</div>
                            <div class="value">
                                <?= floor($integral) ?>
                            </div>
                        </div>
                    </div>
                </div>
                <?php
            }
            ?>
        </div>
    </div>
    <div class="banner">
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <?php
                foreach ($wap_fbanner as $item) {
                    $href = '';
                    if ($item['link_url']) {
                        $link_url = $item['link_url'];
                        $href = " href='$link_url' ";
                    }
                    ?>
                    <div class="swiper-slide">
                        <a <?= $href ?> > <img src="<?= $item['image_url'] ?>"></a>
                    </div>
                    <?php
                }
                ?>
                <!-- <div class="swiper-slide">
                   <a href="http://www.baidu.com"> <img src="<? /*= $web */ ?>/images/mall-m/index-banner.jpg"></a>
                </div>-->
            </div>
            <!-- 如果需要分页器 -->
            <div class="swiper-pagination"></div>
        </div>
        <script>
            $(function () {
                var swiperBanner = new Swiper('.banner .swiper-container', {
                    direction: 'horizontal',
                    autoplay: 3000,
                    autoplayDisableOnInteraction: false,
                    speed: 800,
                    loop: true,

                    // 如果需要分页器
                    pagination: '.swiper-pagination'
                })
            });
        </script>
    </div>
    <div class="classify">
        <a class="classify-list" href="virtual-coupon-list?institution_code=<?= $institution_code ?>">
            <img src="<?= $web ?>/images/mall-m/classify-welfare-icon.png"/>
            <p>免费福利</p>
        </a>
        <!--        <a class="classify-list" href="lottery-zp?institution_code=--><? //= $institution_code ?><!--">-->
        <!--            <img src="--><? //= $web ?><!--/images/mall-m/classify-sweepstake-icon.png"/>-->
        <!--            <p>天天抽奖</p>-->
        <!--        </a>-->
        <a class="classify-list" href="goods-list?cv=1&goodsExtendCategoryCode=c39f1edc-c2a7-11e6-aacd-6c0b8481e2be&goodsListTitle=品质生鲜&institution_code=<?= $institution_code ?>">
            <img src="<?= $web ?>/images/mall-m/classify-sweepstake-icon.png"/>
            <p>品质生鲜</p>
        </a>
        <a class="classify-list" href="game-list?institution_code=<?= $institution_code ?>">
            <img src="<?= $web ?>/images/mall-m/classify-game-icon.png"/>
            <p>休闲游戏</p>
        </a>
        <?php $scene_tmp = $scene[1]; ?>
        <a class="classify-list" href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
            <img src="<?= $web ?>/images/mall-m/classify-mom-icon.png"/>
            <p>母婴专区</p>
        </a>
        <?php $scene_tmp = $scene[2]; ?>
        <a class="classify-list" href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
            <img src="<?= $web ?>/images/mall-m/classify-household-icon.png"/>
            <p>精致家居</p>
        </a>
        <?php $scene_tmp = $scene[3]; ?>
        <a class="classify-list" href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
            <img src="<?= $web ?>/images/mall-m/classify-appliance-icon.png"/>
            <p>精品家电</p>
        </a>
        <?php $scene_tmp = $scene[4]; ?>
        <a class="classify-list" href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
            <img src="<?= $web ?>/images/mall-m/classify-fresh-icon.png"/>
            <p>生鲜食品</p>
        </a>
        <?php $scene_tmp = $scene[5]; ?>
        <a class="classify-list" href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
            <img src="<?= $web ?>/images/mall-m/classify-beauty-icon.png"/>
            <p>美颜护肤</p>
        </a>


    </div>
    <div class="scene-frame">
        <div class="scene-block">
            <?php $scene_tmp = $scene[6]; ?>
            <a href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
                <img class="scene-1" src="<?= $scene_tmp['image_url'] ?>">
            </a>
            <div class="block-right">
                <?php $scene_tmp = $scene[7]; ?>
                <a href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
                    <img class="scene-2" src="<?= $scene_tmp['image_url'] ?>">
                </a>
                <?php $scene_tmp = $scene[8]; ?>
                <a href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
                    <img class="scene-3" src="<?= $scene_tmp['image_url'] ?>">
                </a>
                <?php $scene_tmp = $scene[9]; ?>
                <a href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
                    <img class="scene-4" src="<?= $scene_tmp['image_url'] ?>">
                </a>
            </div>
        </div>
        <div class="scene-list">
            <?php
            foreach ($extendCategoryList_1 as $item) {
                $link_url = $item['link_url'];
//                type为2 link_url要换成产品扩展分类列表链接
                ?>
                <a class="scene-item" href="<?= $link_url ?>">
                    <img src="<?= $item['image_url'] ?>">
                </a>

                <?php
            }
            ?>
        </div>

    </div>
    <script>
        $(function () {
            $('.tangible-benefits').each(function () {
                var count = $(this).data('count');
                var list = $(this).find('.list');
                var item = $(this).find('.list-content');
                var itemWidth = $(item).width() + parseInt($(item).css('margin-left')) + parseInt($(item).css('margin-right'));
                var more = $(this).find('.more');
                var moreWidth = $(more).width() + parseInt($(more).css('margin-left')) + parseInt($(more).css('margin-right'));
                $(list).width(itemWidth * count + moreWidth + 50);
            });
        });
    </script>
    <?php
    foreach ($extendCategoryList_2 as $item) {
        $goodsList = \app\models\MallFrontEnd::getIndexExtendCategoryIndexShowGoodsList($institution_code, $item['id']);
//                type为2 link_url要换成产品扩展分类列表链接
        $link_url = Url::to(['mall-m/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $item['id'], 'goodsListTitle' => '' . $item['name'], 'institution_code' => $institution_code]);
        ?>

        <div class="tangible-benefits" data-count="<?= count($goodsList) ?>">
            <a href="<?= $link_url ?>">
                <img class="title-img" src="<?= $item['image_url'] ?>"/>
            </a>
            <div class="tangible-content">
                <div class="list">
                    <?php
                    foreach ($goodsList as $item) {
                        ?>
                        <a class="list-content" href="<?= Url::to(['mall-m/goods-detail', 'goods_code' => $item['goods_code'], 'institution_code' => $institution_code]) ?>">
                            <img src="<?= $item['goods_image'] ?>">
                            <div class="list-name"><?= $item['name'] ?></div>
                            <div class="integral">
                                <p class="num"><?= $integral_unit ?>:<?= intval($item['selling_integral']) ?></p>
                            </div>
                        </a>
                        <?php
                    }
                    ?>

                    <a class="more" href="<?= $link_url ?>">
                        <p>查<br/>看<br/>更<br/>多</p>
                        <img src="<?= $web ?>/images/mall-m/more-icon.png"/>
                    </a>

                </div>

            </div>
        </div>
        <?php
    }
    ?>


    <?php
    //如果没有特价产品，隐藏
    if (count($activityBargainList) > 0) {
        ?>
        <!--特价专区-->
        <div class="bargain-frame">
            <a class="bargain-title" href="<?= Url::to(['mall-m/goods-list', 'isActivity' => 1, 'goodsListTitle' => '特价专区', 't' => time(), 'institution_code' => $institution_code]) ?>">
                <img src="<?= $web ?>/images/mall-m/index-bargain-title.jpg">
            </a>
            <div class="bargain-content-frame">
                <div class="swiper-container">
                    <div class="swiper-wrapper">
                        <?php
                        foreach ($bargainGoodsList as $item) {
                            ?>
                            <div class="swiper-slide">
                                <a class="goods-item" href="<?= Url::to(['mall-m/goods-detail', 'goods_code' => $item['goods_code'], 'institution_code' => $institution_code]) ?>">
                                    <img src="<?= $item['image_url'] ?>@140w">
                                    <div></div>
                                </a>
                            </div>
                            <?php
                        }
                        ?>
                        <!--                     <div class="swiper-slide">
                                                 <a class="goods-item">
                                                     <img src="images/mall-m/11.jpg">
                                                     <div></div>
                                                 </a>
                                             </div>-->
                    </div>
                </div>
                <script>
                    var swiperBargain = new Swiper('.bargain-content-frame .swiper-container', {
                        slidesPerView: 3,
                        spaceBetween: 35,
                        freeMode: true,
                        freeModeSticky: true,
                        autoplayDisableOnInteraction: false,
                        loop: true,
                        speed: 1000,
                        autoplay: 1000
                    });
                </script>
            </div>
        </div>
        <?php
    }
    ?>
    <div class="hot-frame">
        <!--        <a class="hot-title">-->
        <!--            <img src="--><? //= $web ?><!--/images/mall-m/index-hot-title.jpg">-->
        <!--        </a>-->
        <div class="hot-title">热销精选</div>
        <div class="goods-grid-frame">
            <?php
            foreach ($hotGoodsList as $item) {
                ?>
                <a class="goods-item" href=" <?= Url::to(['mall-m/goods-detail', 'goods_code' => $item['code'], 'institution_code' => $institution_code]) ?>">
                    <img src="<?= $item['image_url'] ?>@300w">
                    <label class="name crossborder">
                        <?php
                        if ($item['is_crossborder'] == '1') {
                            ?>
                            <span>跨境</span>
                            <?php
                        }
                        ?>
                        <?= $item['name'] ?></label>
                    <label class="price"><?= $item['integral_unit'] ?>：<?= intval($item['selling_integral']) ?></label>
                </a>
                <?php
            }
            ?>
            <!-- <a class="goods-item" href="http://www.baidu.com">
                <img src="<? /*= $web */ ?>/images/mall-m/1.jpg">
                <label class="name">呆萌抱抱大肚圣诞陶瓷杯大肚圣圣诞老人</label>
                <label class="price">积分：1198</label>
            </a>-->

        </div>
    </div>
    <?= MallMBottomToolbarWidget::widget(['actionName' => 'index']) ?>
    <div class="back-top"></div>

    <?php
    if ($card != null) {
        ?>
        <div style="display: block;">
            <script type="application/javascript">
                $(function () {
                    $(".window-btn").animate({"right": "-.5rem"}, 300);
                    $("body,html").css({height: "100%", overflow: "hidden"});
                });
            </script>
            <div class="window-btn">
                <p>礼卡兑换</p>
            </div>

            <div class="popup">
                <div class="heade">
                    <img class="head-img" src="<?= $web ?>/images/mall-m/popup-head-img.png"/>
                    <div class="close-btn">
                        <img class="close-btn-img" src="<?= $web ?>/images/mall-m/popup-close-btn.png"/>
                    </div>
                </div>
                <div class="popup-title-img f-l">
                    <img src="<?= $web ?>/images/mall-m/popup-title-2.png"/>
                </div>

                <?php
                if (count($card['goods_list']) > 0) {
                    ?>
                    <a href="goods-detail?goods_code=<?= $card['goods_list'][0]['code'] ?>&institution_code=<?= $institution_code ?>">
                        <div class="big-commodity f-r">
                            <img src="<?= $card['goods_list'][0]['image'] ?>@250w"/>
                            <p class="title"><?= $card['goods_list'][0]['name'] ?></p>
                        </div>
                    </a>
                    <?php
                }
                ?>

                <div class="center-commodity">
                    <?php
                    for ($i = 1; $i < count($card['goods_list']); $i++) {
                        if ($i > 6) {
                            break;
                        }
                        ?>
                        <a href="goods-detail?goods_code=<?= $card['goods_list'][$i]['code'] ?>&institution_code=<?= $institution_code ?>">
                            <div class="f-l content">
                                <img src="<?= $card['goods_list'][$i]['image'] ?>@166w"/>
                                <p class="title"><?= $card['goods_list'][$i]['name'] ?></p>
                            </div>
                        </a>
                        <?php
                    }
                    ?>
                </div>
                <a href="<?= Url::to(['mall-m/goods-list', 'integralFrom' => 0, 'integralTo' => intval($userIntegral), 'sort' => 2, 'institution_code' => $institution_code]) ?>" class="popup-more-btn"></a>
            </div>

            <div class="shade"></div>
        </div>
        <?php
    }
    ?>
</div>

<script type="application/javascript">
    $(function () {
        $(document).scroll(function () {
            var scrollTop = $(document).scrollTop();
            if (scrollTop > 500) {
                $('.back-top').show(500);
                $('.header-download').hide(500);
            } else {
                $('.back-top').hide(500);
                if (app_download == 1) {
                    $('.header-download').show(500);
                }

            }

            $('.header-fixed .header-fixed-bg').css('opacity', scrollTop / 1000);
        });

        $('.back-top').click(function () {
            $('body,html').animate({scrollTop: 0}, 200);
        });


        $(".window-btn").click(function () {
            $(".popup").show(300);
            $(".shade").animate({"opacity": "show"}, 300);
            $(".window-btn").animate({"right": "-.5rem"}, 300);
            $(".window-btn p").animate({"opacity": "hide"}, 300);
            $("body,html").css({height: "100%", overflow: "hidden"});
        });
        $(".close-btn,.shade").click(function () {
            $(".popup").hide(300);
            $(".shade").animate({"opacity": "hide"}, 300);
            $(".window-btn").animate({"right": "0"}, 300);
            $(".window-btn p").animate({"opacity": "show"}, 300);
            $("body,html").css({overflow: "auto", height: "auto"});
        });
    });
</script>